

export default class Session {
    constructor(user) {
        this.user = user
        
    }

    save(chats, callback){
        let d = JSON.stringify(chats);
        console.log(d);
        fetch("/save_session",{
            method:"post",
            headers:{
                "Content-Type":"application/json",
            },
            body:d,
        }).then(d=>d.json()).then(data=>{
            console.log(data)
            callback(data)
        })
    }
    load(callback){
        fetch("/get_sessions",{
            method:"get",
            headers:{
                "Content-Type":"application/json",
            },
        }).then(d=>d.json()).then(data=>{
            console.log("get sessions:",data)
            callback(data)
        })
    }
    del(chats, sessionId, call){
        delete chats[sessionId];
        console.log(chats)
        this.save(chats,call)
    }
}